package cn.ydw_03_netty.sendobject.coder;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import org.msgpack.MessagePack;

/**
 * 编码类
 * Created by ydw on 2017/6/28.
 */
public class MsgpackEncoder extends MessageToByteEncoder<Object> {
    @Override
    protected void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out)
            throws Exception {
        MessagePack msgPack = new MessagePack();
        System.out.println(msg == null);
        System.out.println("开始编码");
        byte[] raw = null;
        raw = msgPack.write(msg);//把对象编码成byte数组
        out.writeBytes(raw);
    }
}
